<template>
  <div class="page">
    <!-- 表单 -->
    <a-card>
      <ComVxeTable
        :columns="columns"
        :axios="page"
        :fromItem="fromItem"
        :formData="formData"
        :initialize="initialize"
        rowId="jobid"
        @checkboxChange="checkboxChange"
        ref="xTable"
      >
        <template #button>
          <vxe-button
            type="submit"
            status="primary"
            content="批量打印"
            @click="batchPrint"
          ></vxe-button>
        </template>
        <template #operate="data">
          <vxe-button
            type="submit"
            status="primary"
            content="查看"
            @click="checkView(data.row)"
          ></vxe-button>
          <vxe-button
            type="submit"
            status="primary"
            content="打印"
            @click="printClick(data.row)"
          ></vxe-button>
        </template>
      </ComVxeTable>
    </a-card>
    <flow-every-modal  ref="modal" :state="false">
      <template #default="records">
        <flow-check-table
          v-if="records.visbled"
          :sqsx="records.sqsx"
          :cyxpjl="records.cyxpjlList"
          :job="records.job"
          :sqsxid="records.sqsxid"
          :change="records.change"
          :disabled="true"
          :nextNodeDbrList="records.nextNodeDbrList"
          :nextNode="records.nextNode"
        ></flow-check-table>
      </template>
      <template #footer>
        <div></div>
      </template>
    </flow-every-modal>
    <printDailyEvaluations ref="printRefName" />
  </div>
</template>

<script>
// 已完成
import flowEveryModal from "../components/stayflow/stayflow-every-modal.vue";
import { everydayPage,queryRckpStatJbxx,queryBatchJobByJobIds,downMyQm } from "../api/dayPort";
import flowCheckTable from "@/views/everydayCheck/components/stayflow/stayflow-check-table";
import ComVxeTable from "../components/vxe-table/com-vxe-table.vue";
import printDailyEvaluations from './printDailyEvaluations.vue'
export default {
  props: ["type"],
  components: { ComVxeTable, flowEveryModal, flowCheckTable, printDailyEvaluations },
  name: "LoadPage",

  data() {
    return {
      columns: [
        {
          type: "checkbox",
          width:'60',
        },
        {
          type: "seq",
          title: "序号",
          width: "60",
        },
        {
          field: "fqymc",
          title: "企业名称",
          width: "200",
        },
        {
          field: "fsxmc",
          title: "事项名称",
          width: "200",
        },
        {
          field: "fslbh",
          title: "受理编号",
          width: "150",
        },
        {
          field: "fslsj",
          title: "接收时间",
          width: "150",
        },
        {
          field: "fhjmc",
          title: "当前环节",
          width: "150",
        },

        {
          title: "操作",
          content:'查看',
          field: "operate",
          width: 200,
          slots: { default: "operate", fixed: "right" },
          fixed: "right"
        },
      ],
      queryParams: {},
      config: {},
      data: [],
      allAlign: null,
      formData: {
        fsxmc: "",
        fqymc: "",
        fslsj: "",
        fjzrq: "",
      },
      fromItem: [
        {
          field: "fsxmc",
          title: "事项名称",
          type:'input',
          itemRender: {},
          slots: { default: "name_item" },
        },
        {
          field: "fqymc",
          title: "企业名称",
          type:'input',
          itemRender: {},
          slots: { default: "name_item" },
        },
      ],
      page: everydayPage,
      initialize: {
        fhjmc: "已完成日常考评",
        fblzt: "待办",
        sfcxgr:'否',
        
      },
      checkboxArr:[]
    };
  },
  created() {},
  mounted() {},

  methods: {
    //选择表格
    checkboxChange(val,records){
      //console.log('选择表格',val)
      this.checkboxArr = val
    },
    batchPrint(){
      if(this.checkboxArr.length){
        queryBatchJobByJobIds({jobids:this.checkboxArr.join(',')}).then(res=>{
          if(res.code == 200){
            var signatureData = []
            var list = []
            res.result.forEach((item,index) => {
                downMyQm({id:item.sqsx.frckpdshblrid}).then(res=>{
                  downMyQm({id:item.sqsx.frckpdfhblrid}).then(res2=>{
                    item['HandledBy'] = "data:image/png;base64," + 
                    btoa( new Uint8Array(res).reduce( (data, byte) => data + String.fromCharCode(byte), "" ))
                    item['ReviewedBy'] = "data:image/png;base64," + 
                    btoa( new Uint8Array(res2).reduce( (data, byte) => data + String.fromCharCode(byte), "" ))
                    list[index] = item
                    signatureData.push(item.sqsx.frckpdfhblrid)
                    //console.log('没有长度吗？',signatureData)
                    //console.log('没有长度吗？',this.checkboxArr.length * 2)
                    if(list.length == this.checkboxArr.length){
                      this.$refs.printRefName.getData(list)
                    }
                  })
                })
                
            });
            
          }else{
            this.$message.warning(res.messsage)
          }
        })
      }else{
        this.$message.warning('请选择打印项')
      }

    },
    printClick(val){
      //console.log('打印项',val)
      if(val.jobid){
        queryBatchJobByJobIds({jobids:val.jobid}).then(res=>{
          if(res.code == 200){
            var signatureData = []
            var list = []
            res.result.forEach((item,index) => {
                downMyQm({id:item.sqsx.frckpdshblrid}).then(res=>{
                    item['HandledBy'] = "data:image/png;base64," + 
                    btoa( new Uint8Array(res).reduce( (data, byte) => data + String.fromCharCode(byte), "" ))
                    list[index] = item
                    if(signatureData.indexOf(item.sqsx.frckpdshblrid) == -1){
                      signatureData.push(item.sqsx.frckpdshblrid)
                    }
                    downMyQm({id:item.sqsx.frckpdfhblrid}).then(res=>{
                      item['ReviewedBy'] = "data:image/png;base64," + 
                      btoa( new Uint8Array(res).reduce( (data, byte) => data + String.fromCharCode(byte), "" ))
                      list[index] = item
                      if(signatureData.indexOf(item.sqsx.frckpdfhblrid) == -1){
                        signatureData.push(item.sqsx.frckpdfhblrid)
                      }
                      //console.log('没有长度吗？',signatureData)
                      if(signatureData.length == 2){
                        this.$refs.printRefName.getData(list)
                      }
                    })
                })
                
            });
          }else{
            this.$message.warning(res.messsage)
          }
        })
      }else{
        this.$message.warning('未获取到当前项')
      }
      

    },
    checkView(row) {
      //console.log(row);
      //console.log(row.jobid);
      this.$refs.modal.handler(row.jobid);
    },
  },
};
</script>

<style lang="less" scoped>
// @import "../assets/table.less";
@import url("../assets/table.less");
</style>
